﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using T4Template.Entities;

namespace T4Template.Dal
{
    class CodeTemplateDal
    {
        private static List<CodeTemplate> _db = new List<CodeTemplate>();
        private static int _count = 0;
        private static CodeTemplateDal _instance = null;

        public static CodeTemplateDal GetInstance(){
            if(_instance==null){
                _instance = new CodeTemplateDal();
            }

            return _instance;
        }

        public CodeTemplate Get(SearchCriteria criteria)
        {
            CodeTemplate foundTemplate = null;
            foreach (CodeTemplate entity in _db)
            {
                if (entity.CodeType == criteria.CodeType &&
                    entity.PatternType == criteria.PatternType)
                {
                    foundTemplate = entity;
                }
            }

            return foundTemplate;
        }

        public void Add(CodeTemplate entity)
        {
            entity.Id = ++_count;
            _db.Add(entity);
        }
    }
}
